#define F_CPU 1000000UL //128000UL // 10 000 000UL

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

#include "smasher/cpp-noalloc.hpp"
//#include "smasher/cpp-alloc.hpp"
#include "smasher/led.h"
#include "smasher/ports.h"


using namespace smasher;

PortD portD;

LED dioda(portD, 0, true);

ISR(TIMER1_COMPA_vect)
{
    dioda.toggle();
}

int main (void)
{
    TCCR1B |= (1 << WGM12); // Configure timer 1 for CTC mode

    TIMSK |= (1 << OCIE1A); // Enable CTC interrupt

    sei(); //  Enable global interrupts

    OCR1A   = 15624; // Set CTC compare value to 1Hz at 1MHz AVR clock, with a prescaler of 64

    TCCR1B |= ((1 << CS10) | (1 << CS11)); // Start timer at Fcpu/64

    LED dioda4(portD, 4, false);

    for (;;)
    {
        _delay_ms(200);
        dioda4.lightOn();
        _delay_ms(200);
        dioda4.lightOff();
    }
}
